package com.wu.controller;

import com.wu.response.CommonReturnType;
import com.wu.service.CommentReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.wu.constant.Constant.DEFAULT_NULL_VALUE;
import static com.wu.constant.Constant.ONE;

/**
 * @author: 吴磊
 * @program: blog
 * @create: 2021-05-13 16:10
 */
@RestController
@Api(tags = "评论举报")
public class CommentReportController {
    @Autowired
    private CommentReportService commentReportService;

    /**
     * 添加举报
     *
     * @param articleId
     * @param commentId
     * @param commentContent
     * @param reportReason
     * @param added
     * @return
     */
    @ApiOperation(value = "添加评论举报")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章Id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "commentId", value = "评论Id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "commentContent", value = "评论内容", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "reportReason", value = "举报原因", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "added", value = "补充说明", dataTypeClass = String.class)
    })
    @RequestMapping(value = "/insertCommentReport", method = RequestMethod.POST)
    public CommonReturnType insertCommentReport(
            @RequestParam(name = "articleId") String articleId,
            @RequestParam(name = "commentId") String commentId,
            @RequestParam(name = "commentContent") String commentContent,
            @RequestParam(name = "reportReason") String reportReason,
            @RequestParam(name = "added", required = false, defaultValue = DEFAULT_NULL_VALUE) String added
    ) {
        commentReportService.insertCommentReport(articleId, commentId, commentContent, reportReason, added);
        return CommonReturnType.create(null);
    }

    /**
     * 通过举报Id获取举报的详细信息
     *
     * @param reportId
     * @return
     */
    @ApiOperation(value = "通过举报Id获取举报的详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "举报Id", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/getCommentReportById", method = RequestMethod.POST)
    public CommonReturnType getCommentReportById(@RequestParam("reportId") String reportId) {
        Map<String, Object> map = commentReportService.getCommentReportById(reportId);
        return CommonReturnType.create(map);
    }

    /**
     * 删除或通过评论举报
     *
     * @param reportId
     * @param type     type为空就说明举报不成功，只删除举报，否则删除此评论的一切相关东西
     * @return
     */
    @ApiOperation(value = "删除或通过评论举报")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "举报Id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "type为空就说明举报不成功，只删除举报，否则删除此评论的一切相关东西", dataTypeClass = String.class)
    })
    @RequestMapping(value = "/deleteCommentReportById", method = RequestMethod.POST)
    public CommonReturnType deleteCommentReportById(@RequestParam("reportId") String reportId,
                                                    @RequestParam(name = "type", required = false, defaultValue = DEFAULT_NULL_VALUE) String type) {
        commentReportService.deleteCommentReportById(reportId, type);
        return CommonReturnType.create(null);
    }


    /**
     * 获取所有的举报
     *
     * @return
     */
    @ApiOperation(value = "删除或通过评论举报")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", defaultValue = ONE, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/getAllCommentReport", method = RequestMethod.POST)
    public CommonReturnType getAllCommentReport(@RequestParam(name = "curPage", defaultValue = ONE) Integer curPage) {
        Map<String, Object> allArticleReport = commentReportService.getAllCommentReport(curPage);
        return CommonReturnType.create(allArticleReport);
    }

}
